<?php

class TestimonialsResource extends Resource
{
    const ID = "testimonials";

    public function GetId()
    {
        return self::ID;
    }

    public function GetFreshData()
    {
        $xml = Core::TestimonialsSubstitutions()->Process( @file_get_contents( TESTIMONIALS_FILE ) );
        $doc = Util::CreateXmlDocument( $xml );
        if ( $doc )
        {
            $testimonials = array();
            $xpath = new XPathHelper($doc);
            $nodes = $xpath->GetNodes("/testimonials/item");
            foreach ( $nodes as $node )
            {
                 $testimonial = new Testimonial();
                 $testimonial->name             = $xpath->GetText("name",               $node);
                 $testimonial->photo            = $xpath->GetText("photo",              $node);
                 $testimonial->main_page_photo  = $xpath->GetText("main_page_photo",    $node);
                 $testimonial->info             = $xpath->GetText("info",               $node);
                 $testimonial->text             = $xpath->GetText("text",               $node);
                 $testimonial->short_text       = $xpath->GetText("short_text",         $node);
                 $testimonial->time             = $xpath->GetText("time",               $node);

                 $testimonial->main_page_photo = ( $testimonial->main_page_photo == null ) ? "" : $testimonial->main_page_photo;

                 $testimonials[] = $testimonial;
            }

            Core::SetProperty('testimonials_count', count($testimonials));

            return $testimonials;
        }
        return null;
    }
}

?>
